package com.genghis.rapidcrm.web.view.language;

import com.genghis.rapidcrm.web.view.language.BaseLanguageHandler;
import org.springframework.context.MessageSource;

import java.util.Locale;

/**
 * @author xulixin
 */
public class RapidLanguageHandler extends BaseLanguageHandler {

    public static final String RAPID_LANGUAGE_HANDLER_KEY = "rapidLanguageHandler";

    private final Locale locale;

    public RapidLanguageHandler(Locale locale, MessageSource messageSource) {
        super(messageSource);
        this.locale = locale;
    }

    public String vtranslate(String key, String module) {
        return vtranslate(key, module, new Object[]{});
    }

    public String vtranslate(String key, String module, Object... args) {
        String formattedString = getLanguageTranslatedString(locale, key, module);
        if (args != null && args.length > 0) {
            formattedString = String.format(formattedString, args);
        }
        return formattedString;
    }

    /**
     * Function that returns current language
     * @return <String> - locale name
     */
    public String getShortLanguageName() {
        return locale.toString();
    }

    public String export(String moduleName, String type) {
        return export(moduleName, type, this.locale);
    }
}
